package com.mobile.web.config.datasource;


import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

/**
 * 多数据源配置
 *
 * @author Administrator
 */
@Configuration
public class DataSourceConfig {

    @Bean(name = "db1")
    @ConfigurationProperties(prefix = "spring.datasource.mysql")
    public DataSource mysqlDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Primary
    @Bean(name = "mysqlTransactionManager")
    public DataSourceTransactionManager mysqlTransactionManager(@Qualifier("db1") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

//    //德州鲲程账套
//    @Bean(name = "db2")
//    @ConfigurationProperties(prefix = "spring.datasource.sqlserver")
//    public DataSource sqlserverDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    //上海鲲程账套
//    @Bean(name = "db3")
//    @ConfigurationProperties(prefix = "spring.datasource.sqlservershkc")
//    public DataSource sqlserverDataSource667() {
//        return DataSourceBuilder.create().build();
//    }

}


